package com.baizhi.service.Impl;

import com.baizhi.entity.Product;
import com.baizhi.mapper.ProductMapper;
import com.baizhi.service.ProductService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.xml.crypto.Data;
import java.util.Date;
import java.util.List;
@Service
@Transactional
public class ProductServiceImpl implements ProductService {
    @Autowired
    private ProductMapper productMapper;
    @Override
    public PageInfo<Product> selectAll(int pageNo,int pageSzie) {
        PageHelper.startPage(pageNo,pageSzie);
        List<Product> products = productMapper.selectList(null);
        return new PageInfo<>(products);
    }

    @Override
    public void delete(int id) {
        QueryWrapper<Product> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("book_id",id);
        productMapper.delete(queryWrapper);
    }

    @Override
    public void add(Product product) {
        Date date = new Date();
        product.setBookId(0);
        product.setGroundingDate(new Date());
        product.setPress("大地出版社");
        product.setEditNum(1);
        product.setPrintCount(4);
        product.setISBN("12345678");
        product.setWordCount("50000");
        product.setPageCount("300");
        product.setStyle("16开");
        product.setPage("胶版纸");
        product.setPack("精装");
        product.setSalenum(555);
        product.setCustomeScore(4.5);
        product.setRecommend("recommend:这真是一本好书啊");
        product.setMessages("message:这真是一本好书啊");
        product.setAuthorMsg("author_msg:作者是好人");
        product.setList("我的目录很详细");
        product.setMediaComment("这真是一本好书啊");
        product.setImagePath("好，非常畅销!难得的一本好书");
        product.setSeriesName("我的丛书");
        product.setDangprice(50.0);
        productMapper.insert(product);
    }

    @Override
    public Product selectById(int bookId) {
        Product product=productMapper.selectById(bookId);
        return product;
    }

    @Override
    public void update(Product product) {
        productMapper.updateById(product);
    }
}
